<!DOCTYPE html>
<html>
<head>
<include file="Include:meta" />
<title>添加项目开票-目的地运营集团数据管理平台</title>
<include file="Include:style" />
<style>
	.w50{ width: 50px; }
</style>
</head>
<body>
<include file="Include:header" />
<include file="Include:left" />
	<div id="main">
		<div class="crumbs">
			<div class="crumbs-text">项目款项列表 > 添加项目开票</div>
		</div>
		<div id="content">
			<form action="__APP__/Financial/invoice_add" method="post" id="project_add_form">
				<input type="hidden" name="action" value="add">
				<input type="hidden" name="mode" value="{$mode}">
				<div class="form-main">
					<div class="form-title">添加项目开票</div>
					<div class="form-item">
						<div class="input-label"><span class="asterisk">*</span>项目编号/名称</div>
						<div class="input-item">
							<select name="fid" class="form-control w400 required_select" autocomplete="off">
								<option value="-10">请选择</option>
								<foreach name="funds" item="vo">
								<option value="{$vo['id']}">[{$vo['project_num']}]{$vo['project_name']}</option>
								</foreach>
							</select>
							<span class="error-item">必填项</span>
						</div>
					</div>
					<div class="form-item">
						<div class="input-label">合同金额</div>
						<div class="input-item ht_money">
							
						</div>
					</div>
					<div class="form-item">
						<div class="input-label">合同日期</div>
						<div class="input-item ht_date">
							
						</div>
					</div>
					<div class="form-item">
						<div class="input-label"><span class="asterisk">*</span>款项阶段</div>
						<div class="input-item">
							<select name="tid" class="form-control w200 required_select" autocomplete="off">
								<option value="-10">请先选择项目</option>
							</select>
							<span class="error-item">必填项</span>
						</div>
					</div>
					<div class="form-item">
						<div class="input-label">该阶段应开票金额</div>
						<div class="input-item money_1">
							
						</div>
					</div>
					<div class="form-item">
						<div class="input-label">该阶段已开票金额</div>
						<div class="input-item money_2">
							
						</div>
					</div>
					<div class="form-item">
						<div class="input-label"><span class="asterisk">*</span>本次开票金额</div>
						<div class="input-item">
							<input type="text" class="form-control required_text w100" name="money" autocomplete="off">
							<span class="error-item">必填项</span>
							<span class="error-item">必须为正整数</span>
						</div>
					</div>
					<div class="form-item">
						<div class="input-label"><span class="asterisk">*</span>本次开票日期</div>
						<div class="input-item">
							<input type="text" name="date" class="form-control Wdate w100 required_text" onClick="WdatePicker()" readonly autocomplete="off">
							<span class="error-item">必填项</span>
						</div>
					</div>
					<div class="form-item">
						<div class="input-label"><span class="asterisk">*</span>发票编号</div>
						<div class="input-item">
							<input type="text" class="form-control required_text w200" name="invoice" autocomplete="off">
							<span class="error-item">必填项</span>
							<span class="error-item">必须为正整数</span>
						</div>
					</div>
				</div>
				<div class="form-btn-item"><input type="submit" value="提交" class="btn btn-submit"><button class="btn btn-default goback" type="button">返回</button></div>
			</form>
		</div>
	</div>
</body>
<include file="Include:javascript" />
<script type="text/javascript">
	$(function() {
		/*编号联动*/
		$("[name='fid']").change(function(){
			var val = $(this).val();
			if(val==-10){
				$('.ht_money,.ht_date').html('');
				$('.money_2,.money_1').html('');
				$("[name='tid']").html("<option value='-10'>请选择</option>").select2();
			}else{
				$.ajax({
					type:"POST",
					async:false,
					dataType:"json",
					data:{"fid":val,"action":"funds"},
					url:"__APP__/Financial/project_funds_ajax",
					success:function(data){
						$('.ht_money').html(data.detail.contract_money);
						$('.ht_date').html(data.detail.contract_date);
						var html = "<option value='-10'>请选择</option>";
						for(var i=0;i<data.info.length;i++){
							html+= "<option value='"+data.info[i].id+"' money_k='"+data.info[i].money_k+"' money_y='"+data.info[i].money_y+"'>"+data.info[i].stage+"</option>"
						}
						$("[name='tid']").html(html).select2();
					}
				})
				$('.money_2,.money_1').html('');
			}
		})
		/*阶段联动*/
		$("[name='tid']").change(function(){
			var val = $(this).val();
			if(val==-10){
				$('.money_2,.money_1').html('');
			}else{
				var k = $(this).find("option:selected").attr("money_k"),
					y = $(this).find("option:selected").attr("money_y");
				$('.money_2').html(k);
				$('.money_1').html(y);
			}
		})
		/*表单验证*/
		$(".btn-submit").click(function(){
			var tag = false;
			
			$("[name='money']").each(function(){
				var val = $(this).val();
				if(val!='' && !/^[1-9]\d*$/.test(val)){
					$(this).nextAll('.error-item').eq(1).show();
					tag = true;
				}
			})
			$('.required_text').each(function(){
				var val = $(this).val();
				if(val==''){
					$(this).next('.error-item').show();
					tag = true;
				}
			})
			$('.required_select').each(function(){
				var val = $(this).val();
				if(val==-10){
					$(this).siblings('.error-item').show();
					tag = true;
				}
			})
			if(tag){
				return false;
			}
		});

		/*取消错误提示*/
		$('.required_select').change(function(){
			$(this).siblings('.error-item').hide();
		})
		$('.required_text,.td_text').focus(function(){
			$(this).nextAll('.error-item').hide();
		})
	});
</script>
</html>